import IntegrationTable, { IntegrationTableProps, ModalProps, OperatingItem } from '@/components/IntegrationTable'
import { DynamicFormItem } from '@/components/DynamicForm'
import React, { useEffect, useState, useRef } from 'react'
import { TableColumnProps, Button, Descriptions } from 'antd'
import { arrayToObject, getArray } from 'phinney-toolkit'
import type { ProColumns, ActionType } from "@ant-design/pro-table";

// @page 题库管理
const GoodsVerify: React.FC = () => {
    // 组件是否已经卸载
    let isUnMounted = false
    let actionref:any = useRef()
    // 文章列表
    const [articleList, setArticleList] = useState([])
    // 题目分类列表
    const [questionTypeList, setQuestionTypeList] = useState([])
    // goodsType
    const [goodsTypeList, setGoodsTypeList] = useState([])
    let filterForm: any = useRef()
    let [selectTab, setSelectTab] = useState(1)


    // 标题样式
    const titleStyle: any = {
        fontSize: '16px',
        lineHeight: '40px',
        padding: 0,
        fontWeight: 600,
    }

    // 表格项
    const columns: ProColumns[] = [
        {
            title: '条目ID',
            dataIndex: 'id',
            search: false
        },
        {
            title: '用户名',
            dataIndex: 'goodsTitle',
            search: false
        },
        {
            title: '手机号',
            dataIndex: 'goodsDesc',
            search: {
				transform: (value: any) => ({
					startTime: value[0],
					endTime: value[1],
				}),
			},
        },
        {
            title: '支付方式',
            dataIndex: 'goodsPrice',
            search: false
        },
        {
            title: '提现金额',
            dataIndex: 'goodsType',
            search: false
        },
        {
            title: '提现时间',
            dataIndex: 'createTime',
            search: false
        },
        {
            title: '状态',
            dataIndex: 'auditTime',
            search: false
        }
    ]

    // 已审核表格项
    const columns2: ProColumns[] = [
        {
            title: '条目ID',
            dataIndex: 'id',
            search: false
        },
        {
            title: '用户名',
            dataIndex: 'goodsTitle',
            search: false
        },
        {
            title: '手机号',
            dataIndex: 'goodsDesc',
            search: {
				transform: (value: any) => ({
					startTime: value[0],
					endTime: value[1],
				}),
			},
        },
        {
            title: '支付方式',
            dataIndex: 'goodsPrice',
            search: false
        },
        {
            title: '提现金额',
            dataIndex: 'goodsType',
            search: false
        },
        {
            title: '提现时间',
            dataIndex: 'createTime',
            search: false
        },
        {
            title: '状态',
            dataIndex: 'auditTime',
            search: false
        }
    ]

    // 一体化表格props
    const tablePorps: IntegrationTableProps = {
        rowKey: 'id',
        scroll: { x: 1000 },
        columns:selectTab==1?columns:columns2,
        listProps: {
            url: '/withdraw/list',
            method: "GET",
            paramsHandle: ({ addTime, ...params }: any) => {

                return {
                    ...params,
                    auditStatus: params.auditStatus || 10
                };
            },
        },
        ref:(refs:any)=>{
            actionref = refs?.actionRef
            filterForm = refs?.filterForm
        },
        headerTitle: (addBtn: any, actionRef: any) => {
            console.log(actionRef,'->>>actionRef')
            return (
                <>
                    <Button
                        type={selectTab == 1 ? "primary" : "default"}
                        onClick={() => {
                            setSelectTab(1)
                            actionRef?.reload?.(1,{
                                status: 10,
                              })
                        }}
                    >待审核</Button>
                    <Button
                        type={selectTab == 2 ? "primary" : "default"}
                        onClick={() => {
                            setSelectTab(2)
                            actionRef?.reload?.(1,{
                                status: 20
                              })
                        }}
                    >已审核</Button>
                </>
            )
        },
        handleOperating: selectTab == 1 ? (items: OperatingItem[]) => {
            return [
                {
                    type: "pop",
				    props: {
					    url: "/goods/audit-goods",
					    method: "POST",
					    popProps: {
						    title: "确定要通过审核吗?",
					    },
					    btnText: "通过",
					    paramsHandle: (params: any, record: any) => {
						    return { ...params, auditStatus: 0, id: record.id };
					    },
				    },
                },
                {
                    type: 'modal',
                    props: {
                        url: "/goods/audit-goods",
						method: "POST",
                        btnText: '驳回',
                        modalProps: {
                            width: 600,
                            title: '驳回原因',
                            bodyStyle: { padding: 0 },
                            formItems: [
                                {
                                    type: "text",
                                    name: "reason",
                                    label: "驳回原因",
                                    required: false,
                                },
                            ],
                            formValuesHandle: (record: any) => {
                                return {
                                    ...record,
                                };
                            },
                        },
                        paramsHandle: (params: any, record: any) => {
                            console.log("-----", record);
                           console.log(record,'_>>>>.111111')

                            return { ...params, auditStatus: 0 };
                        },
                    }
                },
            ]
        } : () => {
            return []
        },
        
        
    }

    // 初始化加载数据
    useEffect(() => {
        return () => {
            isUnMounted = true
        }
    }, [])

    return (
        <IntegrationTable {...tablePorps} />
    )
}

export default GoodsVerify
